package com.hanthink.web.controller.app.message;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hanthink.common.constant.HttpStatus;
import com.hanthink.common.core.controller.BaseController;
import com.hanthink.common.core.page.TableDataInfo;
import com.hanthink.system.domain.message.NewsRecordInfo;
import com.hanthink.system.domain.repair.RequestFileInfo;
import com.hanthink.system.domain.resourcecall.CallRecordFile;
import com.hanthink.system.service.message.IMessageInfoService;
import com.hanthink.system.service.repair.IRequestFileInfoService;

@RestController
@RequestMapping("/app/message/messageInfo")
public class MessageInfoControll extends BaseController {

	@Autowired
	private IMessageInfoService msgService;
	
	@Autowired
	private IRequestFileInfoService requestFileInfoService;

	// 查询消息列表
	@PostMapping("/list")
	public TableDataInfo list(@RequestBody NewsRecordInfo info) {
		startPage();
		List<NewsRecordInfo> list = msgService.selectMsgList(info);
		return getDataTable(list);
	}


	// 更新已读消息
	@PostMapping("/update")
	public void update(@RequestBody NewsRecordInfo info) {
		startPage();
		msgService.updateMsgIsRead(info);
	}

	@PostMapping("/isread")
	public void isread(@RequestBody NewsRecordInfo info) {
		//startPage();
		msgService.updateMsgIsRead(info);
	}

	// 查询消息多媒体列表
	@PostMapping("/queryFilelist")
	public TableDataInfo queryFilelist(@RequestBody NewsRecordInfo info) {

		// 判断消息类型
		TableDataInfo rspData = new TableDataInfo();
		rspData.setCode(HttpStatus.SUCCESS);
		rspData.setMsg("操作成功");
		if (info.getNewsType() != null && !"".equals(info.getNewsType())) {
			CallRecordFile callRecordFile = null;
			switch (info.getNewsType()) {
			case "1": // 资源呼叫类
				callRecordFile = new CallRecordFile();
				callRecordFile.setCallId(info.getId());
				List<CallRecordFile> files = msgService.queryFilelist(callRecordFile);
				rspData.setRows(files);
				break;
			case "2": // 设备报修类
				callRecordFile = new CallRecordFile();
				callRecordFile.setCallId(info.getId());
				List<RequestFileInfo> fileInfos = requestFileInfoService.SelectFileByRequestId(info.getId());
				rspData.setRows(fileInfos);
				break;
			default:
				break;
			}

		}else{
			rspData.setCode(HttpStatus.ERROR);
			rspData.setMsg("无对应多媒体信息");
		}
		return rspData;
	}
}
